import { createRouter, createWebHistory } from 'vue-router'

import Home from '../views/home.vue'
import Blogs from '../views/blogs.vue'
import Map from '../views/map.vue'
import Services from '../views/services.vue'
import BlogsDetail from '../views/blogs-detail.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL), //createWebHashHistory(), //hash模式
  routes: [
    {
      name: 'home',
      path: '/',
      redirect: '/home'
    },
    {
      path: '/home',
      name: 'homeIndex',
      component: Home
    },
    {
      path: '/blogs',
      name: 'blogs',
      component: Blogs
    },
    {
      path: '/blogs-detail',
      name: 'blogsDetail',
      component: BlogsDetail
    },
    {
      path: '/map',
      name: 'Map',
      component: Map
    },
    {
      path: '/services',
      name: 'services',
      component: Services
    }
  ],
  scrollBehavior(to, from, next) {
    return { top: 0 }
  }
})

// // 路由拦截
// router.beforeEach((to, from, next) => {
//   // 这里可以添加路由拦截逻辑
//   // 例如：检查用户认证
//   if (to.path !== '/login' && to.path !== '/register' && !localStorage.getItem('token')) {
//     next('/login') // 未认证，重定向到登录页
//   } else {
//     next() // 继续
//   }
// })

export default router
